package com.hh.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hh.entity.ProdComm;
import com.hh.service.ProdCommService;
import com.hh.vo.ProdCommResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author 辉辉 2022/8/17 9:59
 */
@RestController
@RequestMapping("/prod/prodComm")
@Api(tags = "商品的评论管理接口")
public class ProdCommController {
    @Resource
    private ProdCommService prodCommService;

    @GetMapping("/page")
    @ApiOperation("分页查询商品的评论")
    @PreAuthorize("hasAuthority('prod:prodComm:page')")
    public ResponseEntity<IPage<ProdComm>> prodCommPage(Page<ProdComm> page, ProdComm prodComm) {
        IPage<ProdComm> prodCommIPage = prodCommService.findProdConnPage(page, prodComm);
        return ResponseEntity.ok(prodCommIPage);
    }

    @GetMapping("/prodComm/prodCommData")
    @ApiOperation("前台查询商品的评论总览")
    public ResponseEntity<ProdCommResult> getFrontProdComm(Long prodId) {
        ProdCommResult prodCommResult = prodCommService.findFrontProdComm(prodId);
        return ResponseEntity.ok(prodCommResult);
    }

    // -------前台的接口----------

    @GetMapping("/prodComm/prodCommPageByProd")
    @ApiOperation("分页查询前台评论")
    public ResponseEntity<IPage<ProdComm>> getFrontProdCommPage(Page<ProdComm> page, Long prodId, Integer evaluate) {
        IPage<ProdComm> prodCommIPage = prodCommService.getFrontProdCommPage(page, prodId, evaluate);
        return ResponseEntity.ok(prodCommIPage);
    }
}
